#!usr/bin/env python3
import random

'''
#获取指定长度(最多26个)的随机字母
@param length 需要的长度
@param splitStr 字符串之间的间隔符
@param isLower 是否小写
'''
def getRandChr(length,splitStr='-',isLower=False):
    maxLen = 26
    if length>maxLen:
        raise Exception("单次最多获取26个")
    first = ord('a') if isLower else ord('A') #python的三目运算    
    ls1 = [chr(i+first) for i in range(maxLen)] #先生成26字母
    ls2 = random.sample(ls1,length) #随机获取指定长度    
    return splitStr.join(ls2)
    
#获取不限制长度的随机字母
def getMoreRandChr(length,splitStr='-',isLower=False):
    maxLen = 26
    ret = ""
    fix = ""
    while(length>maxLen):
        if ret!="":
            fix = splitStr
        ret = ret+fix+getRandChr(maxLen,splitStr,isLower)
        length -= maxLen
    if ret!="":
        fix = splitStr          
    ret = ret+fix+getRandChr(length,splitStr,isLower)
    return ret
    
#获取一个随机密匙
def getSecretKey():
    numStr = "%.10f"%random.random()
    numStr = numStr.split('.')[1]
    chr = getMoreRandChr(26,'',True)
    randstr = numStr+chr   
    randstr = ''.join(random.sample(randstr,len(randstr)))
    return randstr
